/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package VIEW;

import CONTROLLERS.CartController;
import datechooser.beans.DateChooserCombo;
import javax.swing.JTable;

/**
 *
 * @author RPhDsmbrana
 */
public class ReportsSales extends javax.swing.JPanel {
    static CartController cartController;
    /**
     * Creates new form ReportsSales
     */
    public ReportsSales() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        salesHistory = new javax.swing.JTable();
        dateChooserComboFrom = new datechooser.beans.DateChooserCombo();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        dateChooserComboTo = new datechooser.beans.DateChooserCombo();

        salesHistory.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        salesHistory.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "Date", "Product Name", "Quantity", "Receipt Number", "Remarks", "Serial Number", "Sales Type"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(salesHistory);

        dateChooserComboFrom.addSelectionChangedListener(new datechooser.events.SelectionChangedListener() {
            public void onSelectionChange(datechooser.events.SelectionChangedEvent evt) {
                dateChooserComboFromOnSelectionChange(evt);
            }
        });
        dateChooserComboFrom.addCommitListener(new datechooser.events.CommitListener() {
            public void onCommit(datechooser.events.CommitEvent evt) {
                dateChooserComboFromOnCommit(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        jLabel2.setText("From:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        jLabel3.setText("To:");

        dateChooserComboTo.addSelectionChangedListener(new datechooser.events.SelectionChangedListener() {
            public void onSelectionChange(datechooser.events.SelectionChangedEvent evt) {
                dateChooserComboToOnSelectionChange(evt);
            }
        });
        dateChooserComboTo.addCommitListener(new datechooser.events.CommitListener() {
            public void onCommit(datechooser.events.CommitEvent evt) {
                dateChooserComboToOnCommit(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 858, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(61, 61, 61)
                .addComponent(jLabel2)
                .addGap(7, 7, 7)
                .addComponent(dateChooserComboFrom, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(125, 125, 125)
                .addComponent(jLabel3)
                .addGap(5, 5, 5)
                .addComponent(dateChooserComboTo, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dateChooserComboFrom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(dateChooserComboTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 454, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void dateChooserComboFromOnSelectionChange(datechooser.events.SelectionChangedEvent evt) {//GEN-FIRST:event_dateChooserComboFromOnSelectionChange
        cartController.updateSalesHistory();
    }//GEN-LAST:event_dateChooserComboFromOnSelectionChange

    private void dateChooserComboFromOnCommit(datechooser.events.CommitEvent evt) {//GEN-FIRST:event_dateChooserComboFromOnCommit
        cartController.updateSalesHistory();
    }//GEN-LAST:event_dateChooserComboFromOnCommit

    private void dateChooserComboToOnSelectionChange(datechooser.events.SelectionChangedEvent evt) {//GEN-FIRST:event_dateChooserComboToOnSelectionChange
        cartController.updateSalesHistory();
    }//GEN-LAST:event_dateChooserComboToOnSelectionChange

    private void dateChooserComboToOnCommit(datechooser.events.CommitEvent evt) {//GEN-FIRST:event_dateChooserComboToOnCommit
        cartController.updateSalesHistory();
    }//GEN-LAST:event_dateChooserComboToOnCommit

    public static JTable getSalesHistoryTable(){
        return salesHistory;
    }
    
    public static DateChooserCombo getDateTo(){
        return dateChooserComboTo;
    }
    
    public static DateChooserCombo getDateFrom(){
        return dateChooserComboFrom;
    }
    
    public static void updateSalesHistoryTable(){
        cartController.updateSalesHistory();
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private static datechooser.beans.DateChooserCombo dateChooserComboFrom;
    private static datechooser.beans.DateChooserCombo dateChooserComboTo;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private static javax.swing.JTable salesHistory;
    // End of variables declaration//GEN-END:variables
}
